package cn.com.bluemoon.daps.api.model.factory;

import cn.com.bluemoon.daps.api.model.RemoteDapDataModelSystemTagMiddleService;
import cn.com.bluemoon.daps.api.model.RemoteDapModelFieldRenameRecordService;
import cn.com.bluemoon.daps.common.constant.ServiceNameConstants;
import cn.com.bluemoon.daps.common.domain.ResultBean;
import cn.com.bluemoon.daps.common.toolkit.FeignClientTools;
import cn.com.bluemoon.daps.model.entity.DapDataModelFieldRenameRecord;
import cn.com.bluemoon.daps.model.entity.DapDataModelSystemTagMiddle;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class RemoteDapDataModelFieldRenameRecordServiceFallbackFactory implements FallbackFactory<RemoteDapModelFieldRenameRecordService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteDapDataModelFieldRenameRecordServiceFallbackFactory.class);

    @Override
    public RemoteDapModelFieldRenameRecordService create(Throwable throwable) {
        log.error("字段命名记录服务调用失败:{}", throwable.getMessage());
        return new RemoteDapModelFieldRenameRecordService() {
            @Override
            public ResultBean<List<DapDataModelFieldRenameRecord>> renameRecordList(String tableId, String fieldId) {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, ServiceNameConstants.DapsApiModel.PROD_SERVICE, "获取记录接口调用失败");
            }
            @Override
            public ResultBean<String> deleteRecord(String tableId, String fieldId) {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, ServiceNameConstants.DapsApiModel.PROD_SERVICE, "删除记录接口调用失败");
            }
        };
    }
}
